package com.jinlia.show.modules.openservice.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Slf4j
@Service
public class TianXingService {
    @Autowired
    RestTemplate restTemplate;

    @Value("${apis.tianapi.mood-poetry}")
    public String moodPoetryUrl;

    /**
     * 情绪诗句:
     * https://www.tianapi.com/apiview/236
     */
    public String moodPoetry() {
        ResponseEntity<String> forEntity = restTemplate.getForEntity(moodPoetryUrl, String.class);
        JSONObject jsonObject = JSON.parseObject(forEntity.getBody());
        log.info("moodPoetry:{}", jsonObject);
        return jsonObject.getJSONObject("result").getString("content");
    }
}
